package org.mch.func.file.filename;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.mch.biz.ui.BizEvent;
import org.mch.biz.ui.BizPanel;
import org.mch.swingm.core.MTextField;
import org.mch.swingm.ext.METextChooser;
import org.mch.swingm.obj.MItem;

import javax.swing.SwingConstants;

/**
 * 描述：文件名操作功能；</BR>
 * 
 * @author MC、ZL；
 * 
 */
public class ClientPanel extends BizPanel {
	private static final long serialVersionUID = 1L;
	private JPanel panel;
	private JRadioButton selAddFileNamePrefix;
	private MTextField textFileNamePrefix;
	private JButton btnExecute;
	private ButtonGroup buttonGroup;
	private JRadioButton selAddFileNameSuffix;
	private MTextField textFileNameSuffix;
	private JRadioButton rdbtn_oldnew;
	private JRadioButton rdbtn_zdwjfolder;
	private JRadioButton rdbtn_filefoldercount;
	private JCheckBox chx_baohanfile;
	private JCheckBox chx_baohanfolder;
	private JCheckBox chx_baohanfilehide;
	private JCheckBox chx_baohanfolderhide;
	private MTextField text_filefolder_count;
	private JCheckBox chx_baohanfolderchild;
	private JCheckBox check_floder;
	private JLabel label_1;
	private MTextField text_filetype;
	private JTabbedPane tabbedPane;
	private JPanel panel_6;
	private JPanel panel_7;
	private JScrollPane scrollPane;
	private JTextArea text_repgz;
	private METextChooser file_path;
	private JCheckBox isFileAndFolderName;
	private JRadioButton rdbtn_filetypeedit;
	private MTextField text_oldfiletype;
	private MTextField text_newfiletype;
	private JLabel label;
	private JCheckBox check_searchchild;

	public ClientPanel() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new BorderLayout(0, 0));
		add(getPanel());
	}

	public JPanel getPanel() {
		if (this.panel == null) {
			this.panel = new JPanel();
			panel.setPreferredSize(new Dimension(200, 10));
			panel.setBorder(new LineBorder(new Color(0, 0, 0)));
			this.panel.setLayout(null);
			getButtonGroup();
			panel.add(getBtnExecute());
			panel.add(getTabbedPane());
			panel.add(getFile_path());
		}
		return this.panel;
	}

	protected BizEvent createEvent() {
		return new ClientEvent(this);
	}

	public JRadioButton getSelAddFileNamePrefix() {
		if (selAddFileNamePrefix == null) {
			selAddFileNamePrefix = new JRadioButton(
					"\u5C06\u5F53\u524D\u76EE\u5F55\u4E0B\u6240\u6709\u6587\u4EF6\u540D\u589E\u52A0\u524D\u7F00\uFF1A");
			selAddFileNamePrefix.setBounds(8, 8, 217, 23);
			selAddFileNamePrefix.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return selAddFileNamePrefix;
	}

	public MTextField getTextFileNamePrefix() {
		if (textFileNamePrefix == null) {
			textFileNamePrefix = new MTextField();
			textFileNamePrefix.setBounds(230, 10, 343, 21);
			textFileNamePrefix.setFont(new Font("宋体", Font.PLAIN, 12));
			textFileNamePrefix.setColumns(10);
		}
		return textFileNamePrefix;
	}

	public JButton getBtnExecute() {
		if (btnExecute == null) {
			btnExecute = new JButton("\u6267\u884C");
			btnExecute.setFont(new Font("宋体", Font.PLAIN, 16));
			btnExecute.setMargin(new Insets(2, 2, 2, 2));
			btnExecute.setBounds(648, 9, 72, 33);
			btnExecute.addMouseListener(getEvent());
		}
		return btnExecute;
	}

	public ButtonGroup getButtonGroup() {
		if (buttonGroup == null) {
			buttonGroup = new ButtonGroup();
			buttonGroup.add(getSelAddFileNamePrefix());
			buttonGroup.add(getSelAddFileNameSuffix());
			buttonGroup.add(getRdbtn_oldnew());
			buttonGroup.add(getRdbtn_zdwjfolder());
			buttonGroup.add(getRdbtn_filefoldercount());
		}
		return buttonGroup;
	}

	public JRadioButton getSelAddFileNameSuffix() {
		if (selAddFileNameSuffix == null) {
			selAddFileNameSuffix = new JRadioButton(
					"\u5C06\u5F53\u524D\u76EE\u5F55\u4E0B\u6240\u6709\u6587\u4EF6\u540D\u589E\u52A0\u540E\u7F00\uFF1A");
			selAddFileNameSuffix.setBounds(8, 53, 217, 23);
			selAddFileNameSuffix.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return selAddFileNameSuffix;
	}

	public MTextField getTextFileNameSuffix() {
		if (textFileNameSuffix == null) {
			textFileNameSuffix = new MTextField();
			textFileNameSuffix.setBounds(230, 53, 343, 21);
			textFileNameSuffix.setFont(new Font("宋体", Font.PLAIN, 12));
			textFileNameSuffix.setColumns(10);
		}
		return textFileNameSuffix;
	}

	public JRadioButton getRdbtn_oldnew() {
		if (rdbtn_oldnew == null) {
			rdbtn_oldnew = new JRadioButton("按文本框中键值对规则逐个替换：");
			rdbtn_oldnew.setBorder(new LineBorder(Color.LIGHT_GRAY));
			rdbtn_oldnew.setBounds(7, 9, 219, 23);
			rdbtn_oldnew.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return rdbtn_oldnew;
	}

	public JRadioButton getRdbtn_zdwjfolder() {
		if (rdbtn_zdwjfolder == null) {
			rdbtn_zdwjfolder = new JRadioButton("将文件夹下指定类型文件的文件名改为其文件夹名");
			rdbtn_zdwjfolder.setBounds(8, 99, 289, 23);
			rdbtn_zdwjfolder.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return rdbtn_zdwjfolder;
	}

	public JRadioButton getRdbtn_filefoldercount() {
		if (rdbtn_filefoldercount == null) {
			rdbtn_filefoldercount = new JRadioButton("统计目录下文件文件夹个数");
			rdbtn_filefoldercount.setBounds(8, 146, 169, 23);
			rdbtn_filefoldercount.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return rdbtn_filefoldercount;
	}

	public JCheckBox getChx_baohanfile() {
		if (chx_baohanfile == null) {
			chx_baohanfile = new JCheckBox("包含文件");
			chx_baohanfile.setBounds(182, 146, 73, 23);
			chx_baohanfile.setFont(new Font("宋体", Font.PLAIN, 12));
			chx_baohanfile.setSelected(true);
		}
		return chx_baohanfile;
	}

	public JCheckBox getChx_baohanfolder() {
		if (chx_baohanfolder == null) {
			chx_baohanfolder = new JCheckBox("包含文件夹");
			chx_baohanfolder.setBounds(260, 146, 85, 23);
			chx_baohanfolder.setFont(new Font("宋体", Font.PLAIN, 12));
			chx_baohanfolder.setSelected(true);
		}
		return chx_baohanfolder;
	}

	public JCheckBox getChx_baohanfilehide() {
		if (chx_baohanfilehide == null) {
			chx_baohanfilehide = new JCheckBox("含隐藏文件");
			chx_baohanfilehide.setBounds(440, 146, 85, 23);
			chx_baohanfilehide.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return chx_baohanfilehide;
	}

	public JCheckBox getChx_baohanfolderhide() {
		if (chx_baohanfolderhide == null) {
			chx_baohanfolderhide = new JCheckBox("含隐藏文件夹");
			chx_baohanfolderhide.setBounds(530, 146, 97, 23);
			chx_baohanfolderhide.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return chx_baohanfolderhide;
	}

	public MTextField getText_filefolder_count() {
		if (text_filefolder_count == null) {
			text_filefolder_count = new MTextField();
			text_filefolder_count.setBounds(632, 148, 64, 19);
			text_filefolder_count.setEditable(false);
			text_filefolder_count.setFont(new Font("宋体", Font.PLAIN, 12));
			text_filefolder_count.setColumns(10);
		}
		return text_filefolder_count;
	}

	public JCheckBox getChx_baohanfolderchild() {
		if (chx_baohanfolderchild == null) {
			chx_baohanfolderchild = new JCheckBox("包含子目录");
			chx_baohanfolderchild.setBounds(350, 146, 85, 23);
			chx_baohanfolderchild.setFont(new Font("宋体", Font.PLAIN, 12));
			chx_baohanfolderchild.setSelected(true);
		}
		return chx_baohanfolderchild;
	}

	public JCheckBox getCheck_floder() {
		if (check_floder == null) {
			check_floder = new JCheckBox("是否修改文件夹名");
			check_floder.setToolTipText("");
			check_floder.setBounds(234, 9, 141, 23);
			check_floder.setFont(new Font("宋体", Font.BOLD, 12));
		}
		return check_floder;
	}

	public JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("文件类型：");
			label_1.setBounds(302, 103, 60, 15);
			label_1.setToolTipText("如：avi  jpg  mp4");
			label_1.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return label_1;
	}

	public MTextField getText_filetype() {
		if (text_filetype == null) {
			text_filetype = new MTextField();
			text_filetype.setBounds(367, 101, 64, 19);
			text_filetype.setText("avi");
			text_filetype.setFont(new Font("宋体", Font.PLAIN, 12));
			text_filetype.setColumns(10);
		}
		return text_filetype;
	}

	public JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.setFont(new Font("宋体", Font.PLAIN, 14));
			tabbedPane.setBounds(10, 49, 865, 533);
			tabbedPane.addTab("基本文件名操作", null, getPanel_6(), null);
			tabbedPane.addTab("文件名称替换", null, getPanel_7(), null);
			tabbedPane.addChangeListener(new ChangeListener() {
				@Override
				public void stateChanged(ChangeEvent e) {
					JTabbedPane tab = (JTabbedPane) e.getSource();
					if (tab.getSelectedComponent() == getPanel_6()) {
						getSelAddFileNamePrefix().setSelected(true);
					} else if (tab.getSelectedComponent() == getPanel_7()) {
						getRdbtn_oldnew().setSelected(true);
					}
				}
			});
		}
		return tabbedPane;
	}

	public JPanel getPanel_6() {
		if (panel_6 == null) {
			panel_6 = new JPanel();
			panel_6.setLayout(null);
			panel_6.add(getTextFileNamePrefix());
			panel_6.add(getSelAddFileNamePrefix());
			panel_6.add(getSelAddFileNameSuffix());
			panel_6.add(getTextFileNameSuffix());
			panel_6.add(getRdbtn_zdwjfolder());
			panel_6.add(getLabel_1());
			panel_6.add(getText_filetype());
			panel_6.add(getRdbtn_filefoldercount());
			panel_6.add(getChx_baohanfile());
			panel_6.add(getChx_baohanfolder());
			panel_6.add(getChx_baohanfolderchild());
			panel_6.add(getChx_baohanfilehide());
			panel_6.add(getChx_baohanfolderhide());
			panel_6.add(getText_filefolder_count());
			panel_6.add(getIsFileAndFolderName());
			panel_6.add(getRdbtn_filetypeedit());
			panel_6.add(getText_oldfiletype());
			panel_6.add(getText_newfiletype());
			panel_6.add(getLabel());
		}
		return panel_6;
	}

	public JPanel getPanel_7() {
		if (panel_7 == null) {
			panel_7 = new JPanel();
			panel_7.setLayout(null);
			panel_7.add(getRdbtn_oldnew());
			panel_7.add(getCheck_floder());
			panel_7.add(getScrollPane());
			panel_7.add(getCheck_searchchild());
		}
		return panel_7;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(7, 44, 656, 450);
			scrollPane.setViewportView(getText_repgz());
		}
		return scrollPane;
	}

	public JTextArea getText_repgz() {
		if (text_repgz == null) {
			text_repgz = new JTextArea();
		}
		return text_repgz;
	}

	public METextChooser getFile_path() {
		if (file_path == null) {
			file_path = new METextChooser(new MItem("目录："));
			file_path.setBounds(10, 9, 626, 34);
			file_path.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		}
		return file_path;
	}

	public JCheckBox getIsFileAndFolderName() {
		if (isFileAndFolderName == null) {
			isFileAndFolderName = new JCheckBox("是否包含文件夹");
			isFileAndFolderName.setSelected(true);
			isFileAndFolderName.setFont(new Font("宋体", Font.PLAIN, 13));
			isFileAndFolderName.setBounds(581, 30, 129, 24);
		}
		return isFileAndFolderName;
	}

	public JRadioButton getRdbtn_filetypeedit() {
		if (rdbtn_filetypeedit == null) {
			rdbtn_filetypeedit = new JRadioButton("将文件夹下指定类型文件改为其其它类型文件，即修改文件后缀！");
			rdbtn_filetypeedit.setFont(new Font("宋体", Font.PLAIN, 12));
			rdbtn_filetypeedit.setBounds(8, 190, 382, 23);
		}
		return rdbtn_filetypeedit;
	}

	public MTextField getText_oldfiletype() {
		if (text_oldfiletype == null) {
			text_oldfiletype = new MTextField();
			text_oldfiletype.setText("asp");
			text_oldfiletype.setFont(new Font("宋体", Font.PLAIN, 12));
			text_oldfiletype.setColumns(10);
			text_oldfiletype.setBounds(398, 191, 64, 19);
		}
		return text_oldfiletype;
	}

	public MTextField getText_newfiletype() {
		if (text_newfiletype == null) {
			text_newfiletype = new MTextField();
			text_newfiletype.setText("html");
			text_newfiletype.setFont(new Font("宋体", Font.PLAIN, 12));
			text_newfiletype.setColumns(10);
			text_newfiletype.setBounds(496, 191, 64, 19);
		}
		return text_newfiletype;
	}

	public JLabel getLabel() {
		if (label == null) {
			label = new JLabel("→");
			label.setFont(new Font("Dialog", Font.BOLD, 13));
			label.setHorizontalAlignment(SwingConstants.CENTER);
			label.setBounds(463, 193, 28, 16);
		}
		return label;
	}

	public JCheckBox getCheck_searchchild() {
		if (check_searchchild == null) {
			check_searchchild = new JCheckBox("是否搜索子文件夹");
			check_searchchild.setToolTipText("");
			check_searchchild.setFont(new Font("宋体", Font.BOLD, 12));
			check_searchchild.setBounds(388, 8, 141, 23);
		}
		return check_searchchild;
	}
}